﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Maxleaf.EDI.API.Contract;
using Maxleaf.EDI.API.Contract.Admin.Commands;
using Maxleaf.EDI.API.Contract.Admin.Parameters;
using Maxleaf.EDI.Infrastructure;

namespace Maxleaf.EDI.Admin.ExternalServices
{
    public class AdminService :IAdminService
    {
        public AuthenticateResult Authenticate(AuthenticateParameters parameters)
        {
            using (var client = this.GetClient())
            {
                return client.Proxy.Authenticate(parameters);
            }
        }

        private ServiceProxy<IAdminService> GetClient()
        {
            var result = new ServiceProxy<IAdminService>("Admin.Point");

            return result;
        }

        public void ResetPassword(ResetPasswordCommand command)
        {
            using (var client = this.GetClient())
            {
                client.Proxy.ResetPassword(command);
            }
        }

        public GetAllUsersResult GetAllUsers(GetAllUsersParameters parameters)
        {
            using (var client = this.GetClient())
            {
                return client.Proxy.GetAllUsers(parameters);
            }
        }

        public GetAllDBsResult GetAllDBs(GetAllDBsParameters parameters)
        {
            using (var client = this.GetClient())
            {
                return client.Proxy.GetAllDBs(parameters);
            }
        }

        public GetAllUsersResult GetUserDBAccess(GetAllUsersParameters parameters)
        {
            using (var client = this.GetClient())
            {
                return client.Proxy.GetAllUsers(parameters);
            }
        }

        public void SetDBAccess(SetDBAccessCommand command)
        {
            using (var client = this.GetClient())
            {
                client.Proxy.SetDBAccess(command);
            }
        }


        public void CreateUser(API.Contract.Admin.Commands.CreateUserCommand command)
        {
            using (var client = this.GetClient())
            {
                client.Proxy.CreateUser(command);
            }
        }
    }
}